#!/usr/bin/env python
# vim: tabstop=4 expandtab shiftwidth=4 softtabstop=4 textwidth=79 autoindent

"""
Python source code
Last modified: 16 Jul 2011 - 14:18
Last author: Laban Mwangi

Simple unit testing for home.co.ke
"""
import unittest
import tempfile
import shutil
import tmr_queens_scraper



class Test(unittest.TestCase):
    def setUp(self):
        """setUp for setting up the test environment"""
        self.tmp_dir = tempfile.mkdtemp()

    def test_cities(self):
        """test_cities verifies that cities do exist"""
        scraper = tmr_queens_scraper.Scrape(tmr_queens_scraper.DEFAULT_URL, self.tmp_dir)
        cities = scraper.getCities()
        self.assertTrue(len(cities) > 0)

    def test_locations(self):
        """test_locations verifies that locations do exist"""
        scraper = tmr_queens_scraper.Scrape(tmr_queens_scraper.DEFAULT_URL, self.tmp_dir)
        cities = scraper.getCities()
        city = cities[0]
        locations = scraper.getLocations(city['title'])
        print locations
        self.assertTrue(len(locations) > 0)

    def test_camera(self):
        """
        test_camera verifies that cameras do exist and tests the images
        returned
        """
        scraper = tmr_queens_scraper.Scrape(tmr_queens_scraper.DEFAULT_URL, self.tmp_dir)
        cities = scraper.getCities()
        city = cities[0]
        locations = scraper.getLocations(city['title'])
        location = locations[0]
        print "\t%s" % location['title']
        scraper.CACHE_PATH = self.tmp_dir
        img = scraper.getImages(location['title'])
        print img
        self.assertTrue(len(img) > 0)

    def tearDown(self):
        """tearDown  cleans up after us"""
        shutil.rmtree(self.tmp_dir)
